﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
using System.Text;

namespace ChequeManagement
{
    public partial class Test : Form
    {
        public Test()
        {
            InitializeComponent();
        }

        DAL.DALPayAndReceive dalPayAndReceiveT = new DAL.DALPayAndReceive();
        BLL.BLLPayAndReceive bllPayAndReceiveT = new BLL.BLLPayAndReceive();
        BLL.BLLDrawer bllDrawer = new BLL.BLLDrawer();

        DAL.DALChequeCategory dalchequeCategoryT = new DAL.DALChequeCategory();
        BLL.BLLChequeCategory bllchequeCategoryT = new BLL.BLLChequeCategory();
        BLL.BLLBank bllBankObject = new BLL.BLLBank();
        BLL.BLLPayAndReceiveItem objBLLPayAndReceiveItem = new BLL.BLLPayAndReceiveItem();
        BLL.BLLPayAndRecieveItemFactory objBLLPayAndReceiveItemFactory = new BLL.BLLPayAndRecieveItemFactory();
        DAL.DALPayAndReceiveItem objDALPayAndReceiveItem = new DAL.DALPayAndReceiveItem();
        BLL.BLLPayAndReceiveItem objBllpayAndReceiveItem = new BLL.BLLPayAndReceiveItem();
        DAL.DALChequeCategoryWithPARI dalChequeCategoryPARITest = new DAL.DALChequeCategoryWithPARI();
        BLL.BLLChequeCategoryWithPARI bllChequeCategoryPARITest = new BLL.BLLChequeCategoryWithPARI();


        private void Test_Load(object sender, EventArgs e)
        {
            payAndReceiveTest();
            chequeCategoryTest();
            chequeCategoryPARITest();
        }

        private void chequeCategoryPARITest()
        {
            DateTime dt = DateTime.Now;

            objBLLPayAndReceiveItem.AcountNo = 1234;
            objBLLPayAndReceiveItem.Amount = 147;
            objBLLPayAndReceiveItem.BranchName = "pasdaran";
            objBLLPayAndReceiveItem.ChequeNo = 1596;
            objBLLPayAndReceiveItem.DateOfIssue = dt;
            objBLLPayAndReceiveItem.Description = "aaaaaaaaaaaaaaaaa";
            objBLLPayAndReceiveItem.Payee = "farshad";

            bllChequeCategoryPARITest.ChequeCategoryObject = bllchequeCategoryT;
            bllChequeCategoryPARITest.PayAndReceiveItemObject = objBLLPayAndReceiveItem;
        }

        private void payAndReceiveTest()
        {

            bllPayAndReceiveT.Date = new DateTime(2010, 12, 1);
            bllPayAndReceiveT.Description = "Ajab";
            bllPayAndReceiveT.Type = BLL.DocumentType.Pay;
            bllDrawer.DrawerID = 1;
            bllPayAndReceiveT.DrawerObj = bllDrawer;
        }

        private void chequeCategoryTest()
        {
            bllBankObject.BankID = 23;
            bllBankObject.BankName = "melli";
            bllchequeCategoryT.AccountNo = 123;
            bllchequeCategoryT.BranchName = "Mirdamad";
            bllchequeCategoryT.ChequeCategoryID = 152345;
            bllchequeCategoryT.ChequeCategoryName = "Jaari!";
            bllchequeCategoryT.FirstPageNo = 500000;
            bllchequeCategoryT.PageCount = 25;

            bllchequeCategoryT.BankObject = bllBankObject;
        }
        private void PayAndReceive_Click(object sender, EventArgs e)
        {

            //Insert
            dalPayAndReceiveT.Insert(bllPayAndReceiveT);
            MessageBox.Show("Successfull Insert");
        }



        private void btnchequecategory_Click(object sender, EventArgs e)
        {
            dalchequeCategoryT.Insert(bllchequeCategoryT);
            MessageBox.Show("Your ChequeCategory successfully is Inserted");

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void FetchAllButton_Click(object sender, EventArgs e)
        {

            //FetchAll
            DataTable dt = new DataTable();
            dalPayAndReceiveT.FetchAll(dt);
            MessageBox.Show("Successfull FetchAll");
        }

        private void UpdateButton_Click(object sender, EventArgs e)
        {
            bllPayAndReceiveT.Description = "Hello";
            dalPayAndReceiveT.Update(bllPayAndReceiveT, 2);
            MessageBox.Show("Successfull Update");
        }

        private void FetchAllObjButton_Click(object sender, EventArgs e)
        {
            List<BLL.BLLPayAndReceive> lp;
            lp = dalPayAndReceiveT.FetchAll();
            MessageBox.Show("Successfull FetchAllObj");
        }

        private void DeleteButton_Click(object sender, EventArgs e)
        {
            dalPayAndReceiveT.Delete(1);
            MessageBox.Show("Successfull Delete");
        }

        private void FetchByFieldButton_Click(object sender, EventArgs e)
        {
            List<BLL.BLLPayAndReceive> lp;
            lp = dalPayAndReceiveT.FetchByField("PayAndReceiveID", (int)2);
            MessageBox.Show("Successfull FetchByFieldObj");
        }

        private void FetchByFieldDT_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dalPayAndReceiveT.FetchByField("PayAndReceiveID", (int)2, dt);
            MessageBox.Show("Successfull FetchByFieldDT");
        }

        private void FetchAllByConditionButton_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            //dalPayAndReceiveT.FetchAllByCondition()
            MessageBox.Show("Successfull FetchAllByCondition");
        }

        private void FetchByKeyButton_Click(object sender, EventArgs e)
        {
            BLL.BLLPayAndReceive bp = new BLL.BLLPayAndReceive();
            bp = dalPayAndReceiveT.FetchByKey(3);
            MessageBox.Show("Successfull FetchByKey");
        }

        private void Insertbtn_Click(object sender, EventArgs e)
        {
            dalchequeCategoryT.Insert(bllchequeCategoryT);
            MessageBox.Show("Successfull Insert");
        }

        private void Updatebtn_Click(object sender, EventArgs e)
        {
            bllchequeCategoryT.AccountNo = 1234;
            dalchequeCategoryT.Update(bllchequeCategoryT, 5);
            MessageBox.Show("Successfull Update");
        }

        private void FetchAllDTbtn_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dalchequeCategoryT.FetchAll(dt);
            MessageBox.Show("Successfull FetchAll");
        }

        private void FetchAllObjbtn_Click(object sender, EventArgs e)
        {
            List<BLL.BLLChequeCategory> lc;
            lc = dalchequeCategoryT.FetchAll();
            MessageBox.Show("Successfull FetchAllObj");
        }

        private void FetchByFieldObjbtn_Click(object sender, EventArgs e)
        {
            List<BLL.BLLChequeCategory> lc;
            lc = dalchequeCategoryT.FetchByField("ChequeCategoryID", (int)5);
            MessageBox.Show("Successfull FetchByFieldObj");
        }

        private void FetchByFieldDTbtn_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dalchequeCategoryT.FetchByField("ChequeCategoryID", (int)5, dt);
            MessageBox.Show("Successfull FetchByFieldDT");
        }

        private void FetchAllByConditionbtn_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dalchequeCategoryT.FetchAllByCondition("AccountNo = 123", dt);
            MessageBox.Show("Successfull FetchAllByCondition");
        }

        #region ChequeCategoryWithPARI Test

        private void FetchByKeybtn_Click(object sender, EventArgs e)
        {
            BLL.BLLChequeCategory bc = new BLL.BLLChequeCategory();
            bc = dalchequeCategoryT.FetchByKey(5);
            MessageBox.Show("Successfull FetchByKey");
        }

        private void Deletebtn_Click(object sender, EventArgs e)
        {
            dalchequeCategoryT.Delete(2);
            MessageBox.Show("Successfull Delete");
        }

        private void InsertChequePARIButton_Click(object sender, EventArgs e)
        {
            try
            {
                dalChequeCategoryPARITest.Insert(bllChequeCategoryPARITest);
                MessageBox.Show("Successful Insert");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void UpdateChequePARIButton_Click(object sender, EventArgs e)
        {
            try
            {
                bllChequeCategoryPARITest.ChequeCategoryObject.ChequeCategoryName = "newChequeCategoryName";
                dalChequeCategoryPARITest.Update(bllChequeCategoryPARITest, objBLLPayAndReceiveItem.ChequeNo);
                MessageBox.Show("Successful Update");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void FetchAllDTChequePARIButton_Click(object sender, EventArgs e)
        {
            try
            {
                DataTable dt = new DataTable();
                dalChequeCategoryPARITest.FetchAll(dt);
                MessageBox.Show("Successful FetchAll DT");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void FetchAllObjChequePARIButton_Click(object sender, EventArgs e)
        {
            try
            {
                List<BLL.BLLChequeCategoryWithPARI> chequePARIList;
                chequePARIList = dalChequeCategoryPARITest.FetchAll();
                MessageBox.Show("Successful FetchAll Object");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        //not done
        private void FetchByKeyObjChequePARIButton_Click(object sender, EventArgs e)
        {
            try
            {
                List<BLL.BLLChequeCategoryWithPARI> lp;
                lp = dalChequeCategoryPARITest.FetchByField("ChequeNo", (int)2);
                MessageBox.Show("Successfull FetchByField Obj");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //not done
        private void FetchByFieldChequePARIButton_Click(object sender, EventArgs e)
        {
            try
            {
                DataTable dt = new DataTable();
                dalChequeCategoryPARITest.FetchByField("ChequeNo", (int)2, dt);
                MessageBox.Show("Successfull FetchByFieldDT");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //not done
        private void FetchConditionChequePARIButton_Click(object sender, EventArgs e)
        {
            try
            {
                //DataTable dt = new DataTable();
                //dalChequeCategoryPARITest.FetchAllByCondition("sd", dt);
                //MessageBox.Show("Successfull FetchAllByCondition");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void FetchByKeyChequePARIButton_Click(object sender, EventArgs e)
        {
            try
            {
                BLL.BLLChequeCategoryWithPARI bp = new BLL.BLLChequeCategoryWithPARI();
                bp = dalChequeCategoryPARITest.FetchByKey(1);
                MessageBox.Show("Successfull FetchByKey");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void DeleteChequePARIButton_Click(object sender, EventArgs e)
        {
            try
            {
                dalChequeCategoryPARITest.Delete(1);
                MessageBox.Show("Successfull Delete");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        #endregion





        private void PAndRItemFetchByFieldDT_Click(object sender, EventArgs e)
        {
            DataTable DT = new DataTable();
            objDALPayAndReceiveItem.FetchByField(BLL.BLLPayAndReceiveItem.PayAndReceiveItemField.Amount, 1, DT);
            MessageBox.Show("OK");
        }

        private void PAndRItemFetchAllByCondition_Click(object sender, EventArgs e)
        {
            DataTable DT = new DataTable();
            objDALPayAndReceiveItem.FetchAllByCondition(" ChequeNo=2456", DT);
            dataGridView1.DataSource = null;
            dataGridView1.DataSource = DT;
            
        }

        private void PAndRItemFetchbyKey_Click(object sender, EventArgs e)
        {
            BLL.BLLPayAndReceiveItem PARItem = new BLL.BLLPayAndReceiveItem();
            DataTable DT=new System.Data.DataTable();
            PARItem = objDALPayAndReceiveItem.FetchByKey(1111);
            MessageBox.Show("OK");
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            objDALPayAndReceiveItem.Delete(2456);
            MessageBox.Show("Deleted");
        }



        private void PAndRItemInsert_Click(object sender, EventArgs e)
        {
            try
            {
                DAL.DALPayAndReceiveItem objdal = new DAL.DALPayAndReceiveItem();
                BLL.BLLPayAndReceiveItem objbll = new BLL.BLLPayAndReceiveItem();
                BLL.BLLBank objbank = new BLL.BLLBank();

                DateTime DT = DateTime.Now;

                objbank.BankID = 1;
                objbank.BankName = "melat";

                objbll.AcountNo = 11;
                objbll.Amount = 550;
                objbll.BankID = 1;
                // objbll.BankObject = objbank;
                objbll.BranchName = "sadeghie";
                objbll.ChequeNo = 1111;
                objbll.DateOfIssue = DT;
                objbll.Description = "BBBBBBBBB";
                objbll.PayAndReceiveID = 1;
                objbll.Payee = "ali";
                objbll.Status = BLL.ChequeStatus.Retrieve; ;

                objdal.Insert(objbll);
                MessageBox.Show("INSERT");

            }
            catch (SqlException ex)
            {

                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void PAndRItemUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                DAL.DALPayAndReceiveItem objdal = new DAL.DALPayAndReceiveItem();
                BLL.BLLPayAndReceiveItem objbll = new BLL.BLLPayAndReceiveItem();

                DateTime DT = DateTime.Now;

                objbll.AcountNo = 10;
                objbll.Amount = 50000;
                objbll.BankID = 2;
                objbll.BranchName = "tehranno";
                objbll.ChequeNo = 2031;
                objbll.DateOfIssue = DT;
                objbll.Description = "WWEEWWEE";
                objbll.PayAndReceiveID = 1;
                objbll.Payee = "Morteza";
                objbll.Status = BLL.ChequeStatus.NotReceipt;

                objdal.Update(objbll, 2456);

                MessageBox.Show("UPDATE");

            }
            catch (SqlException ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void PAndRItemFetchallDT_Click(object sender, EventArgs e)
        {
            try
            {
                DAL.DALPayAndReceiveItem objdal = new DAL.DALPayAndReceiveItem();

                DataTable DT = new DataTable();

                objdal.FetchAll(DT);
                dataGridView1.DataSource = DT;
                
            }
            catch (SqlException ex)
            {

                MessageBox.Show(ex.Message);
            }


        }

        private void PAndRItemFetchallOBJ_Click(object sender, EventArgs e)
        {

            try
            {
                DAL.DALPayAndReceiveItem objdal = new DAL.DALPayAndReceiveItem();
                List<BLL.BLLPayAndReceiveItem> li = new List<BLL.BLLPayAndReceiveItem>();
                DataTable DT = new System.Data.DataTable();
                li = objdal.FetchAll();

                MessageBox.Show("OK");

            }
            catch (SqlException ex)
            {

                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void PAndRItemFetchbyfieldOBJ_Click(object sender, EventArgs e)
        {
            try
            {
                DAL.DALPayAndReceiveItem objdal = new DAL.DALPayAndReceiveItem();
                //objdal.FetchByField("ChequeNo", 1456);
                objdal.FetchByField(BLL.BLLPayAndReceiveItem.PayAndReceiveItemField.ChequeNo, 1456);
                MessageBox.Show("OK");

            }
            catch (SqlException ex)
            {

                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }



        }


    }
}
